package com.asset.dispoal.agent.service.common;

import com.asset.dispoal.agent.dto.SysAgentRequest;
import com.asset.dispoal.agent.domain.db.entity.SysAgent;
import com.asset.dispoal.agent.domain.db.mapper.SysAgentMapper;
import com.asset.dispoal.agent.service.converter.SysAgentConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.core.id.BaseIdeable;
import tech.mhuang.pacebox.springboot.protocol.Result;

/**
 * @author qr
 * @date 2022/3/25$
 */
@Component
public class SysAgentInsertCommand implements BaseCommand<SysAgentRequest, Result> {

    @Autowired
    SysAgentMapper sysAgentMapper;

    @Autowired
    private BaseIdeable<String> ideable;

    @Override
    public Result execute(SysAgentRequest request) {
        SysAgent sysAgent = SysAgentConverter.INSTANCE.resToDo(request);
        sysAgent.setId(ideable.generateId());
        sysAgentMapper.insert(sysAgent);
        return Result.ok();
    }
}
